package com.yanqu.road.server.cmd.wingroom.message;

import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wingroom.WingRoomMessageModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2022/3/20 2:22
 */
@Cmd(code = GameProtocol.S_WING_ROOM_CROSS_GIVE_LIKE_RESP, desc = "跨服点赞返回")
public class CrossGiveLikeRespCmd extends AbstractCommand {
    private long ownerServerId;
    private long ownerUserId;
    private WingRoomProto.GiveMessageLikeRespMsg respMsg;

    @Override

    public boolean parseData(YanQuMessage packet) throws Exception {
        WingRoomProto.GiveLikeCrossRespMsg crossRespMsg = WingRoomProto.GiveLikeCrossRespMsg.parseFrom(packet.getBytes());
        ownerServerId = crossRespMsg.getOwnerServerId();
        ownerUserId = crossRespMsg.getOwnerUserId();
        respMsg = crossRespMsg.getRespMsg();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        player.getModule(WingRoomMessageModule.class).removePreRecord(ownerServerId, ownerUserId);
        if (respMsg.getRet() == 0) {
            player.getModule(WingRoomMessageModule.class).addGiveLikeData(ownerServerId, ownerUserId);
        }
        player.sendPacket(ClientProtocol.U_WING_ROOM_GIVE_MESSAGE_LIKE, respMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
